<?php  
	header('Content-type:text/html;charset=utf-8');
	function isfnum($str){
		$reg="/\D+/";
		preg_match($reg,$str,$result);
		return $result;
	}
	if($_POST){
		$fuhao=$_POST['fuhao'];
		$num1=$_POST['num1'];
		$num2=$_POST['num2'];					
		if(isfnum($num1)||isfnum($num2)){
			$re=0;	
			echo "<script>alert('输入的数字中带有非法字符或没有值输入,请重新输入')</script>";					
		}else{
			switch ($fuhao) {
				case '+':
					$re=$num1+$num2;
					break;
				case '-':
					$re=$num1-$num2;
					break;
				case '*':
					$re=$num1*$num2;
					break;
				default:
					$re=$num1/$num2;
					break;
			}		
		}
	}else{
		$re=0;
	}
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>计算机初级版</title>
		<style type="text/css">
			*{
				margin:0 ;
				padding: 0;
			}
			.box{
				width:400px;
				height:300px;
				/*border:1px solid red;*/
				margin:50px auto ;
			}
			.box #re{
				font: bold 30px/30px "微软雅黑";
				color:red;
			}
			.box label{
				line-height: 30px;
			}
			.box #btn{
				display: block;
				width:120px;
				line-height: 30px;
				text-align: center;
				margin: 10px auto;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<span id="re">
				<?php echo $re; ?>
			</span>
			<form action="" method="post">
				<label for="num1">请输入第一个数字</label>
				<input type="text" name="num1" id="num1" required=""/>
				<br />
				<label for="num2">请输入第二个数字</label>
				<input type="text" name="num2" id="num2" required=""/>
				<br />
				<label for="fuhao">请输入运算符</label>
				<select name="fuhao">
					<option value="+">+</option>
					<option value="-">-</option>
					<option value="*">*</option>
					<option value="/">/</option>
				</select>
				<br />
				<input type="submit" value="运算" id="btn" />
			</form>
		</div>
	</body>
</html>